package spring.boot.client.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import spring.boot.client.codec.Invocation;
import spring.boot.client.message.auth.AuthRequest;
import spring.boot.client.message.chat.ChatSendToAllRequest;
import spring.boot.client.message.chat.ChatSendToOneRequest;
import spring.boot.client.service.NettyMessageService;

@RestController
public class NettyController {

    @Autowired
    private NettyMessageService nettyMessageService;

    @GetMapping("/auth")
    public String auth() {
        AuthRequest authRequest = new AuthRequest();
        authRequest.setAccessToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI0NiIsImV4cCI6MTYzMzE0MjAxOH0.5tVusmKyjQ13ekkGFPHeSafD7YfdCBr4PdQRAcZ85CI");
        // 创建 Invocation 对象
        Invocation invocation = new Invocation(AuthRequest.TYPE, authRequest);
        // 发送消息
        nettyMessageService.send(invocation);
        return "success";
    }


    @GetMapping("/chat/to/one")
    public String chatToOne() {
        ChatSendToOneRequest chatSendToOneRequest = new ChatSendToOneRequest();
        chatSendToOneRequest.setMsgId("900326");
        chatSendToOneRequest.setContent("hello Jack");
        chatSendToOneRequest.setToUserId("46");
        // 创建 Invocation 对象
        Invocation invocation = new Invocation(ChatSendToOneRequest.TYPE, chatSendToOneRequest);
        // 发送消息
        nettyMessageService.send(invocation);
        return "success";
    }

    @GetMapping("/chat/to/all")
    public String chatToAll() {
        ChatSendToAllRequest chatSendToAllRequest = new ChatSendToAllRequest();
        chatSendToAllRequest.setMsgId("12345678");
        chatSendToAllRequest.setContent("Hello Tom");
        // 创建 Invocation 对象
        Invocation invocation = new Invocation(ChatSendToAllRequest.TYPE, chatSendToAllRequest);
        // 发送消息
        nettyMessageService.send(invocation);
        return "success";
    }

}
